<template>
  <div class="home">
    <Header />
    <div class="banner-box">
      <el-carousel class="height-100">
        <el-carousel-item v-for="(banner, bannerIndex) in bannerList" :key="bannerIndex">
          <h3 class="small">
            <div class="bannerimage" >
              <el-image :src="banner.pic" @click="getLink(banner)" style="cursor: pointer"> </el-image>
            </div>
          </h3>
        </el-carousel-item>
      </el-carousel>
      <!-- 分类区域暂时隐藏 -->
      <!-- <div class="content-box" style="z-index: 9999;">
        <el-card class="box-card">
          <div class="card-list" v-for="(list, index) in navListData" :key="index">
            <div class="title">{{ list.name }}</div>
            <div class="flex jc-sb">
              <el-link type="info"  :underline="true" v-for="(category, categoryIndex) in list.childrenList" :key="categoryIndex" @click="tocarCenter(category)">{{ category.name }}</el-link>
            </div>
          </div>
        </el-card>
      </div> -->
    </div>
    <!-- 内容区 -->
    <div class="exhibition-box">
      <div class="content-box">
        <div class="notice-box flex ai-c">
          <div class="login flex">
            <div class="login-icon" @click="goUser">
              <img src="@/assets/carImg.png" />
            </div>
            <div class="login-btn">
              <p v-show="!islogin">您好！请登录</p>
              <p v-show="islogin">您好! {{userinfo.nickname}}</p>
              <el-button v-show="islogin" type="danger" size="mini" @click="goUser()">个人信息</el-button>
              <el-button v-show="!islogin" type="danger" size="mini" @click="login()">登录</el-button>
            </div>
          </div>
          <ul class="service-box flex-1 flex jc-sa">
            <li>
              <el-link type="info" href="#/Customization">
                <img src="@/assets/home-icon-1.jpeg" />
                <span>深度定制</span>
              </el-link>
            </li>
            <li>
              <el-link type="info" href="#/newProduct">
                <img src="@/assets/home-icon-2.jpeg" class="icon-2" />
                <span>新品预售</span>
              </el-link>
            </li>
            <li>
              <el-link type="info" href="#/CarCenter">
                <img src="@/assets/home-icon-3.jpeg" class="icon-3" />
                <span>整车中心</span>
              </el-link>
            </li>
            <li>
              <el-link type="info" href="#/FinanceSupport">
                <img src="@/assets/home-icon-4.jpeg" />
                <span>金融支持</span>
              </el-link>
            </li>
            <li>
              <el-link type="info" href="#/buyCar">
                <img src="@/assets/home-icon-5.jpeg" />
                <span>在线购车</span>
              </el-link>
            </li>
          </ul>
          <div class="notice">
            <p>公共栏</p>
            <div class="notice-info">
              <div v-for="(ins, instructionIndex) in instruction" :key="instructionIndex">
                <a href="javascript:void(0)" @click="toDetail(ins)">{{ins.name}}</a>
              </div>
            </div>
          </div>
        </div>
        <!-- 图表块 -->
        <div class="imginfo-box flex jc-sb">
          <div class="info-img-box flex flex-d ai-c jc-c" v-for="(productCategory,
            productCategoryIndex) in productCategoryhList" :key="productCategoryIndex">
            <h3>{{ productCategory.name }}</h3>
            <span>{{ productCategory.description }}</span>
            <img :src="productCategory.icon" />
          </div>
        </div>
      </div>
    </div>

    <!-- 为你推荐 -->
    <HomeRecommendList :list="recommandList" />
    <!-- 客运、公交、团体旅游、新能源客车、专用客车..... -->
    <HomeCarTypeList :carTypeListData="subjectList" />
    <Footer />
    <!-- dialog -->
    <el-dialog :visible.sync="loginDelog" :close-on-click-modal="false" width="40%">
      <el-form label-position="top" label-width="80px" :model="formLabelAlign">
        <el-form-item label="名称">
          <el-input v-model="formLabelAlign.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="formLabelAlign.pwd"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" @click="submitForm">登录/注册</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import HomeRecommendList from "@/components/HomeRecommendList.vue"; //为你推荐
import HomeCarTypeList from "@/components/HomeCarTypeList.vue"; //客运
export default {
  name: "Home",
  components: {
    Header,
    Footer,
    HomeRecommendList, //为你推荐列表
    HomeCarTypeList //汽车类型组件
  },
  data() {
    return {
      navListData: [],
      islogin: false,
      // 汽车分类数据结构
      carTypeListData: [
        {
          title: "客运",
          data: ["5-6米", "6-7米", "7-8米", "8米以上"],
          leftImg:
            "https://www.chinabuses.com/uploadfile/share/buses/2020/0910/20200910102909250.jpg",
          list: [
            {
              name: "全新3米福顺系列客车",
              des: "简约有型 性价首选",
              price: "600",
              url:
                "https://www.chinabuses.com/uploadfile/share/buses/2020/0912/20200912085028701.jpg"
            },
            {
              name: "全新4米福顺系列客车",
              des: "简约有型 性价首选",
              price: "700",
              url:
                "https://www.chinabuses.com/uploadfile/share/buses/2020/0912/20200912085028701.jpg"
            },
            {
              name: "全新5米福顺系列客车",
              des: "简约有型 性价首选",
              price: "800",
              url:
                "https://www.chinabuses.com/uploadfile/share/buses/2020/0912/20200912085028701.jpg"
            }
          ]
        },
        {
          title: "公交",
          data: ["5-6米", "6-7米", "7-8米", "8米以上", "其他"],
          leftImg:
            "https://www.chinabuses.com/uploadfile/share/buses/2020/0910/20200910102909250.jpg",
          list: [
            {
              name: "全新3米福顺系列客车",
              des: "简约有型 性价首选",
              price: "600",
              url:
                "https://www.chinabuses.com/uploadfile/share/buses/2020/0912/20200912085028701.jpg"
            },
            {
              name: "全新4米福顺系列客车",
              des: "简约有型 性价首选",
              price: "700",
              url:
                "https://www.chinabuses.com/uploadfile/share/buses/2020/0912/20200912085028701.jpg"
            },
            {
              name: "全新5米福顺系列客车",
              des: "简约有型 性价首选",
              price: "800",
              url:
                "https://www.chinabuses.com/uploadfile/share/buses/2020/0912/20200912085028701.jpg"
            }
          ]
        }
      ],
      recommandList: [],
      bannerList: [],
      productCategoryhList: [],
      subjectList: [],
      loginDelog: false,
      formLabelAlign: {},
      userinfo: {},
      instruction: {}
    };
  },
  created() {

    this.category();
    this.contentList();
    if (localStorage.getItem('userinfo')) {
      this.islogin = true;
      this.userinfo = JSON.parse(localStorage.getItem('userinfo'));
    }
    this.getInstructions();
  },
  mounted() { },
  methods: {
      contentList() {
          let _this = this;
          this.$http.get("/home_car/findByAll").then(function (response) {
              _this.recommandList = response.data.productList;
              _this.bannerList = response.data.advertiseList;
              _this.productCategoryhList = response.data.productCategoryhList;
              _this.subjectList = response.data.subjectList[0];
          });
      },
      goUser() {
          this.$router.push("/user")
      },
      category() {
          let _this = this;
          this.$http
              .get("/home_car/findByChildren", {
                  // projectErpCode:this.currentAgent.erp_code
              })
              .then(function (response) {
                  _this.navListData = response.data;
              });
      },
      getInstructions() {
          let _this = this;
          this.$http
              .get("/bot_menu/find-bulletin", {
                  // projectErpCode:this.currentAgent.erp_code
              })
              .then(function (response) {
                  _this.instruction = response.data;
              });
      },
      submitForm() {
      },
      login() {
          this.$router.push({path: '/login', params: {userId: 123}})
      },
      toDetail(item) {
        this.$router.push(`/menudetail?id=${item.id}`)
      },
      tocarCenter(category) {
          this.$router.push({path: '/carCenter', query: {"attrname": category.name, 'attrid': category.id}})
      },
      getLink(banner){
        window.location.href = banner.url;
      }
  }
};
</script>

<!-- <style lang="scss" scoped>-->
<style lang="scss">
//banner区
.banner-box {
  position: relative;
  height: 450px;
  background-color: #d2d2d2;
  color: #ffffff;
  z-index: 0;
  .small,
  .bannerimage {
    height: 100%;
  }
  /deep/ .el-image {
    height: 100%;
  }
  /deep/ .el-carousel__container {
    height: 100%;
  }
  @media (min-width: 801px) {
    /deep/ .el-carousel__indicators {
      bottom: 50px;
    }
  }
}
.box-card {
  position: absolute;
  top: 20px;
  width: 240px;
  text-align: left;
  font-size: 14px;
  color: #636363;
  z-index: 9;

  .card-list {
    margin-bottom: 20px;

    &:last-child {
      margin-bottom: 0;
    }
  }

  .title {
    font-size: 18px;
    color: #cf0a2c;
  }
}
.bannerimage img {
  height: 100%;
  z-index: -1;
  // max-height: 300px;
  /*width:100%;*/
}
//内容区
.exhibition-box {
  .content-box {
    transform: translateY(-50px);
    z-index: 1000 !important;
  }
  .notice-box {
    height: 100px;
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    padding: 10px 20px;
    box-sizing: border-box;
  }
  .login {
    width: 240px;
    .login-icon {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      overflow: hidden;
      border: 1px solid #ccc;
    }
    .login-btn {
      text-align: left;
      margin-left: 10px;
    }
    img {
      width: 100%;
      height: 85%;
    }
    p {
      color: #8e8e8e;
      font-size: 14px;
      margin-bottom: 8px;
    }
  }
  .service-box {
    text-align: center;
    border-left: 1px solid #dcdcdc;
    border-right: 1px solid #dcdcdc;

    img.icon-2 {
      width: 55px;
    }
    img.icon-3 {
      width: 52px;
    }

    img {
      width: 50px;
      height: 50px;
      margin: 0 auto;
      display: block;
    }
    span {
      font-size: 12px;
      color: #414141;
    }
  }
  .notice {
    width: 270px;
    text-align: left;
    p {
      font-size: 14px;
      color: #414141;
      padding-left: 20px;
      line-height: 40px;
    }
    .notice-info {
      font-size: 12px;
      color: #575757;
      padding-left: 20px;
      border-top: 1px solid #dcdcdc;
      line-height: 40px;
      height: 40px;
      box-sizing: border-box;
      overflow: hidden;
    }
  }

  .info-img-box {
    width: 288px;
    background-color: #ffffff;
    border-radius: 10px;
    transform: translateY(50px);
    h3 {
      font-size: 20px;
      color: #333233;
      padding-top: 16px;
      margin-bottom: 15px;
    }
    span {
      font-size: 12px;
      color: #afafaf;
    }
    img {
      width: 54%;
      text-align: center;
      transform: translateY(-10px);
      z-index: -1;
    }
  }
}
/deep/ .el-form-item {
  text-align: left;
  &:last-child {
    text-align: center;
  }
}

/*手机端*/
@media (min-width: 320px) and (max-width: 800px) {
  .box-card {
    display: none;
  }
  .banner-box {
    height: 200px;
  }
  .content-box {
    width: 100%;
    //overflow: hidden;
  }
  .exhibition-box {
    .login {
      display: none;
    }
    .content-box {
      transform: translateY(-0px);
    }
    .service-box {
      border: none;
    }
    .notice-box {
      height: 90px;
      padding: 0;
      border-radius: 0;
    }
    .notice {
      position: absolute;
      top: 100px;
      left: 50%;
      transform: translateX(-50%);
      background: #fff;
      width: calc(100% - 20px);
      z-index: 9;
      border-radius: 4px;
    }
    .imginfo-box {
      margin-top: 50px;
      flex-wrap: wrap;
      justify-content: space-around;
    }
    .info-img-box {
      width: 45%;
      margin-bottom: 10px;
      h3 {
        font-size: 16px;
      }
      img{
        width: 40%;
      }
    }

  }
}
</style>
